home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / os2 / pccts.zip / SYN.H < prev    next >
C/C++ Source or Header  |  1992-12-08  |  6KB  |  172 lines

  1. /*
  2.  * syn.h
  3.  *
  4.  * This file includes definitions and macros associated with syntax diagrams
  5.  *
  6.  * SOFTWARE RIGHTS
  7.  *
  8.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  9.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  10.  * company may do whatever they wish with source code distributed with
  11.  * PCCTS or the code generated by PCCTS, including the incorporation of
  12.  * PCCTS, or its output, into commerical software.
  13.  * 
  14.  * We encourage users to develop software with PCCTS.  However, we do ask
  15.  * that credit is given to us for developing PCCTS.  By "credit",
  16.  * we mean that if you incorporate our source code into one of your
  17.  * programs (commercial product, research project, or otherwise) that you
  18.  * acknowledge this fact somewhere in the documentation, research report,
  19.  * etc...  If you like PCCTS and have developed a nice tool with the
  20.  * output, please mention that you developed it using PCCTS.  In
  21.  * addition, we ask that this header remain intact in our source code.
  22.  * As long as these guidelines are kept, we expect to continue enhancing
  23.  * this system and expect to make other tools available as they are
  24.  * completed.
  25.  *
  26.  * ANTLR 1.06
  27.  * Terence Parr
  28.  * Purdue University
  29.  * 1989-1992
  30.  */
  31.  
  32. #define NumNodeTypes    4
  33. #define NumJuncTypes    9
  34.  
  35. /* List the different node types */
  36. #define nJunction        1
  37. #define nRuleRef        2
  38. #define nToken            3
  39. #define nAction            4
  40.  
  41. /* Different types of junctions */
  42. #define aSubBlk            1
  43. #define aOptBlk            2
  44. #define aLoopBlk        3
  45. #define EndBlk            4
  46. #define RuleBlk            5
  47. #define Generic            6    /* just a junction--no unusual characteristics */
  48. #define EndRule            7
  49. #define aPlusBlk        8
  50. #define aLoopBegin        9
  51.  
  52. typedef int NodeType;
  53.  
  54. #define TreeBlockAllocSize        500
  55. #define JunctionBlockAllocSize    200
  56. #define ActionBlockAllocSize    50
  57. #define RRefBlockAllocSize        100
  58. #define TokenBlockAllocSize        100
  59.  
  60. /* note that 'right' is used by the tree node allocator as a ptr for linked list */
  61. typedef struct _tree {
  62.             struct _tree *down, *right;
  63.             int token;
  64.             union {
  65.                 int rk;    /* if token==EpToken, => how many more tokens req'd */
  66.                 struct _tree *tref;    /* if token==TREE_REF */
  67.                 set sref;            /* if token==SET */
  68.             } v;
  69.         } Tree;
  70.  
  71. /* a predicate is defined to be a predicate action and a token tree with context info */
  72. typedef struct {
  73.     char *expr;
  74.     Tree *context;
  75. } Predicate;
  76.  
  77.                 /* M e s s a g e  P a s s i n g  T o  N o d e s */
  78.  
  79. /*
  80.  * assumes a 'Junction *r' exists.  This macro calls a function with
  81.  * the pointer to the node to operate on and a pointer to the rule
  82.  * in which it is enclosed.
  83.  */
  84. #define TRANS(p)    {if ( (p)==NULL ) fatal("TRANS: NULL object");        \
  85.                     if ( (p)->ntype == nJunction ) (*(fpJTrans[((Junction *)(p))->jtype]))( p );\
  86.                     else (*(fpTrans[(p)->ntype]))( p );}
  87.  
  88. #define PRINT(p)    {if ( (p)==NULL ) fatal("PRINT: NULL object");\
  89.                     (*(fpPrint[(p)->ntype]))( p );}
  90.  
  91. #define REACH(p,k,rk,a){if ( (p)==NULL ) fatal("REACH: NULL object");\
  92.                     (a) = (*(fpReach[(p)->ntype]))( p, k, rk );}
  93.  
  94. #define TRAV(p,k,rk,a){if ( (p)==NULL ) fatal("TRAV: NULL object");\
  95.                     (a) = (*(fpTraverse[(p)->ntype]))( p, k, rk );}
  96.  
  97. /* All syntax diagram nodes derive from Node -- superclass
  98.  */
  99. typedef struct _node {
  100.             NodeType ntype;
  101.         } Node;
  102.  
  103. typedef struct _anode {
  104.             NodeType ntype;
  105.             Node *next;
  106.             char *action;
  107.             int file;            /* index in FileStr (name of file with action) */
  108.             int line;            /* line number that action occurs on */
  109.             int is_predicate;    /* true if action is a <<...>>? predicate action */
  110.             int done;            /* don't dump if action dumped (used for predicates) */
  111.             int init_action;    /* is this the 1st action of 1st prod of block? */
  112.             char *pred_fail;    /* what to do/print when predicate fails */
  113.         } ActionNode;
  114.  
  115. typedef struct _toknode {
  116.             NodeType ntype;
  117.             Node *next;
  118.             char *rname;        /* name of rule it's in */
  119.             int file;            /* index in FileStr (name of file with rule) */
  120.             int line;            /* line number that token occurs on */
  121.             int token;
  122.             int label;            /* token label or expression ? */
  123.             int astnode;        /* leaf/root/excluded (used to build AST's) */
  124.         } TokNode;
  125.  
  126. typedef struct _rrnode {
  127.             NodeType ntype;
  128.             Node *next;
  129.             char *rname;        /* name of rule it's in */
  130.             int file;            /* index in FileStr (name of file with rule)
  131.                                    it's in */
  132.             int line;            /* line number that rule ref occurs on */
  133.             char *text;            /* reference to which rule */
  134.             char *parms;        /* point to parameters of rule invocation
  135.                                    (if present) */
  136.             char *assign;        /* point to left-hand-side of assignment
  137.                                    (if any) */
  138.             int linked;            /* Has a FoLink already been established? */
  139.             int astnode;        /* excluded? (used to build AST's) */
  140.         } RuleRefNode;
  141.  
  142. typedef struct _junct {
  143.             NodeType ntype;
  144.             int visited;        /* used by recursive routines to avoid
  145.                                    infinite recursion */
  146.             char *lock;            /* used by REACH to track infinite recursion */
  147.             char *pred_lock;    /* used by find_predicates to track infinite recursion */
  148.             int altnum;            /* used in subblocks. altnum==0 means not an
  149.                                    alt of subrule */
  150.             int jtype;            /* annotation for code-gen/FIRST/FOLLOW.
  151.                                    Junction type */
  152.             struct _junct *end;    /* pointer to node with EndBlk in it
  153.                                    if blk == a block type */
  154.             Node *p1, *p2;
  155.             char *rname;        /* name of rule junction is in */
  156.             int file;            /* index in FileStr (name of file with rule)
  157.                                    if blk == RuleBlk */
  158.             int line;            /* line number that rule occurs on */
  159.             int halt;            /* never move past a junction with halt==TRUE */
  160.             char *pdecl;        /* point to declaration of parameters on rule
  161.                                    (if present) */
  162.             char *parm;            /* point to parameter of block invocation
  163.                                    (if present) */
  164.             char *ret;            /* point to return type of rule (if present) */
  165.             char *erraction;    /* point to error action (if present) */
  166.             set *fset;            /* used for code generation */
  167.             Tree *ftree;        /* used for code generation */
  168.             Predicate predicate;/* predicate that can be used to disambiguate */
  169. } Junction;
  170.  
  171. typedef struct { Node *left, *right; } Graph;
  172.